using BCW.Friends;
using UnityEngine;

public class TDMGameMode : TeamGameMode
{
	public override void StartRound()
	{
		base.StartRound();
		TDMController.instance.SetStartPVP(true);
		SpawnPointChief.SpawnPoint randomPointForTDM = SpawnPointChief.instance.getRandomPointForTDM(PlayerBehavior.MyPlayer);
		CoroutineRunner.Instance.StartCoroutine(ManagerPreloadingSectors.thisScript.LoadSectorsNearPoint(new Vector2(randomPointForTDM.position.x, randomPointForTDM.position.z)));
		CoroutineRunner.Instance.StartCoroutine(PVPManager.instance.WaitForSectorsLoad(delegate
		{
			BCWDebug.LogError("StartTeamMatch ", "Debug Tdm");
			GameController.instance.showWindowGame();
			TDMController.instance.SetStartPVP(true);
			PlayerBehavior.MyPlayer.FirstSpawn(2f);
			CoroutineRunner.Invoke(2.5f, delegate
			{
				BCWDebug.LogError("HideInterface from start round");
				if (PlayerBehavior.MyPlayer.tController.enabled)
				{
					GameInfoWindow.instance.HideInterface();
					MapWindow.instance.gameObject.SetActive(true);
					GameController.instance.showWindowGame();
				}
			});
		}));
	}

	public override void RestartRound()
	{
		base.RestartRound();
		if (BCWFlagManager.instance != null)
		{
			BCWFlagManager.instance.winerTeam = PunTeams.Team.none;
		}
		if (BCWFlagController.instance != null)
		{
			BCWFlagController.instance.winnerTeam = TDMResult.None;
			if (!PhotonNetwork.isMasterClient)
			{
				BCWFlagController.instance.Reset();
			}
		}
		if (GameController.instance.playerScript != null)
		{
			GameController.instance.playerScript.Points = 0;
		}
		TDMController.instance.WaitTeamAndSpawnPointOnRestart(RestartTeamMatch);
	}

	private void RestartTeamMatch()
	{
		if (FriendsUIGame.instance != null)
		{
			FriendsUIGame.instance.CleanInvitePlayer();
		}
		CoroutineRunner.Instance.StartCoroutine(TDMController.instance.WaitRestartTDM());
	}
}
